ffexviusfandomcom_zh-20200215-history
模块:Data
local p = { equipment = { _class ={'武器', '防具', '首飾'}, _plural = {Clothes = 'Clothes', Staff = 'Staves'}, Dagger = 1, Sword = 1, Sword" = 1, Katana = 1, Staff = 1, Rod = 1, Bow = 1, Axe = 1, Hammer = 1, Spear = 1, Harp = 1, Whip = 1, Weapon" = 1, Gun = 1, Mace = 1, Fist = 1, Shield" = 2, Shield" = 2, Hat = 2, Helm = 2, Clothes = 2, Armor" = 2, Armor" = 2, Robe = 2, Accessory = 3, "短劍" = 1, "劍" = 1, "大劍" = 1, "刀" = 1, "手杖" = 1, "魔棒" = 1, "弓" = 1, "斧" = 1, "鎚" = 1, "長槍" = 1, "樂器" = 1, "鞭" = 1, "投擲武器" = 1, "火槍" = 1, "權杖" = 1, "拳套" = 1, "輕盾" = 2, "重盾" = 2, "帽子" = 2, "頭盔" = 2, "衣服" = 2, "輕甲" = 2, "重甲" = 2, "袍" = 2, "首飾" = 3 } } function p.item(frame) local args, result = {}, {} for k, v in pairs(frame.args) do --Basic cleaning of arguments and argument grouping v = mw.text.trim(v) if v and v~='' then argsk = v end end local function link(v, hide_disambiguation) --Autolinks if does not contain a link. If hide_disambiguation evals true, links "Page (Disambigation)" as "Page (Disambigation)|Page" return v and (string.match(v, '%[%^%[%+%]%]') and v or '[.. (hide_disambiguation and string.gsub(v, '([^%(+) %((^%)+)%)', '%1 (%2)|%1')--sadly pipe trick doesn't work in Lua or v ) .. ']]') end function result:_(v) --simplified version of mw:en:Module:Buffer if v and v ~= '' then table.insert(self, v) end return self end local function split_link(v, hide_disambiguation, sep, alt_link_func) --Splits v by commas and joins with sep (or comma if omitted). Links using link() unless passed alt_link_func local t = {} for _, s in ipairs(mw.text.split(string.gsub(v, "\\,", string.char(127,4,127,2)), ',%s*')) do s = mw.text.trim(s) if s ~= '' then table.insert(t, (alt_link_func or link)(s, hide_disambiguation)) end end return string.gsub(table.concat(t, sep or '、'), string.char(127,4,127,2), ',') end local function multi_split(v, head_format, sep, headless_sep) --Splits lists by semicolons to be passed onto split_link(). If first value contains a colon, uses text in front of colon as group. local result = {_=result._} for _, x in ipairs(mw.text.split(v, ';')) do local group, list = string.match(string.gsub(x, '\\:', string.char(127,4,127,2)), '^(^:+): -(.+)$') group = string.gsub(group, string.char(127,4,127,2), ':') list = string.gsub(list, string.char(127,4,127,2), ':') result :_(group and string.format(head_format, group) or headless_sep) :_(split_link(list or x, nil, group and sep or headless_sep)) :_'\n' end return table.concat(result) end local function ailment_link(v, hide_disambiguation) --Autolinks ailments and effects. When hide_disambiguation false (not nil), will not autolink non-ailments (args.resist) local status, chance = string.match(v, '^(^%(-) ?%((^%)%(-)%)') if status and ({Poison=1, Blind=1, Sleep=1, Silence=1, Paralyze=1, Confuse=1, Disease=1, Petrify=1})status then return string.format('%s (%s)', status, status, chance) end if hide_disambiguation false then return v end return link(v, hide_disambiguation) end local stats_sorted, stats = {}, { HP = {}, MP = {}, "攻擊" = {}, "防禦" = {}, "魔力" = {}, "精神" = {} } if args.type and p.equipmentargs.type then for k, v in pairs(stats) do --grab percents and integers in the form such that DEF+7, DEF+50% is entered as 'DEF=7+50%' if argsk then v2 = string.match(argsk, '%d+%%') if v2 then v1 = string.match(argsk, '^%+?(%d+)%+')--tolerate ATK=+10 else table.insert(v, string.match(argsk,'^%+?(%d+)$')) end end end for i = 1, 2 do --show percentage stats after integer stats for _, v in ipairs{'HP','MP','攻擊','防禦','魔力','精神'} do--this line controls the order that stats appear table.insert(stats_sorted, statsvi and string.format(({'%s+%s','%s +%s'})i, v, statsvi)) end end end local function stats_cell() --generates stats cell used on category/shop pages local only = args.warning and string.match(args.warning, "Useable by '?'?'?(%a+)'?'?'? only") return table.concat(({_=result._}) :_(table.concat(stats_sorted, ' ')) :_(args.element and '屬性：' .. args.element) :_(args.resist and '耐性：' .. split_link(args.resist, false, nil, ailment_link)) :_(args.effect and '效果：' .. split_link(args.effect, nil, nil, ailment_link)) :_(args.ability and '能力：' .. split_link(args.ability)) :_(args.warning and (only and string.format("%ss only", mw.getContentLanguage():ucfirst(only)) or string.gsub(string.format("%s", args.warning), ", ?", " ") )) :_(args.used_by and '專用：' .. split_link(args.used_by)), ' ' ) end local function extend(sep) for _, v in ipairs(frame:getParent().args) do _ = mw.text.trim(mw.text.killMarkers(v)) if _ ~= '' then local a, b = string.match(string.gsub(v, '\\@', string.char(127,4,127,2)), '^(.-)@(.*)') result:_(sep or '\n| '):_( a and (a~='' and ((argsa or a "STATS") and string.format(string.gsub(b, string.char(127,4,127,2), '@'), argsa or a 'STATS' and stats_cell()) or '-') or b and string.gsub(b, string.char(127,4,127,2), '@')) or args_ or v 'STATS' and stats_cell() or '-') end end end local function type_link(parens) return string.format(parens and '（%s）' or '%s', p.equipment._pluralargs.type or args.type, args.type) end local froms, currentTitle, hasExclusiveFX = { {'drop', '掉落：'}, {'steal', '盜取：'}, {'explore', '收集自：'}, {'shop', args.quartz and '胖陸行鳥商店：' or '商店：'}, {'recipe', '配方：'}, {'chest', '寶箱：'}, {'reward', '獎勵：'} }, mw.title.getCurrentTitle().fullText, args.effect and string.match(args.effect, '%(%[%[(%w+)%]%] only%)') args.mode = args.mode or frame:getParent().args.mode or mw.title.getCurrentTitle().namespace 14 and 'category' or frame:getParent():getTitle() ~= currentTitle and (hasExclusiveFX and 'exclusiveFX' or 'item') if args.mode 'category' then --Display when on category page local obtain = {} for i = 1, #froms, 1 do if args[fromsi1] then table.insert(obtain, string.format( "%s %s", fromsi2, split_link(args[fromsi1]) )) end end table.insert(obtain, args.trust and string.format("Trust: %s", args.trust)) table.insert(obtain, args.obtain and multi_split(args.obtain, "%s: ", ', ', ' ')) result :_(string.gsub(string.format('|-\n| align="center" | || %s || ', args.image or 'Icon-' .. args.name .. '.png', link(args.zhname, true)), '@', args.zhname)) :_(stats_cell()) :_' || ' :_(table.concat(obtain, ' ')) extend() elseif args.mode 'exclusiveFX' then --Display when transcluded onto a page which title matches the name of the unit which benefits from an exclusive effect result :_" ' elseif args.mode 'custom' then result:_'|-' extend() elseif args.mode 'fetch' then extend(frame:getParent().args.sep) return table.concat(result, nil, 2, #result) elseif args.mode 'tooltip' then return string.format('%s %s%s %s', link(args.name, true), args.image or string.format('icon-%s.png', args.name), string.gsub(args.name, ' %(%w+%)', ), p.equipmentargs.type and string.format('%s', frame:expandTemplate{title = 'Equip', args = {args.type 'Throwing Weapon' and 'Throwing' or args.type}} ) or '', p.equipmentargs.type and 'Stats: ' .. string.gsub(string.gsub(stats_cell(), '%((%-%d+%%?)%)', '(%1)'), '(^)(%+%d+%%?)', '%1%2') or args.effect or '' ) elseif args.mode then --Display when on a shop page (mode = recipe/item/item2) result :_(string.format(string.gsub('|-\n| %s@\n| %s\n| %s\n| ', '@', args.mode 'item2' and ' ' or '%%s'), args.mode 'recipe' and 'Recipe for ' or '', args.mode 'item2' and args.name or link(args.name, true), args.mode 'recipe' and '-' or args.type, args.mode 'recipe' and '-' or stats_cell(), args.quartz and 'Star Quartz' or 'Gil', args.quartz or ({item=1,item2=1})args.mode and args.buy_gil or args.mode 'recipe' and args.buy_rec or '?' )) :_(frame:getParent().args.limit and string.format(' (Limit: %s)', frame:getParent().args.limit)) extend() else --info displayed on item page local materia = {args.effect} table.insert(materia, args.ability) for k, v in ipairs(materia) do materiak = split_link(v, true, nil, ailment_link) end result :_' \n__NOEDITSECTION__' :_((args.image or args.name) and string.format(' \n \n ', p.equipmentargs.type and 'equip' or string.lower(args.type or ''), args.image or string.format('Icon-%s.png', args.name), args.name or '' )) :_(args.title and "\n\n'" .. args.title .. "") :_(args.desc and '\n\n' .. args.desc) if args.type then if p.equipmentargs.type then result :_"\n 資料 \n\n*類型：'" :_(args.type '首飾' and '首飾' or args.type and p.equipment._class[p.equipmentargs.type] .. type_link(true)) :_"\n*'數據：'" :_(stats_sorted1 and table.concat(stats_sorted, '、') or '-') :_"\n*'屬性：'" :_(args.element or '-') :_"\n*'耐性：'" :_(args.resist and split_link(args.resist, false, nil, ailment_link) or '-') :_"\n*'附加效果：'" :_(args.effect or '-') :_"\n*'附加能力：'" :_(#materia > 0 and (args.ability and string.format("%s\n*'附加能力：'%s" or "\n*'附加能力：'%s", unpack(materia)) or materia1) .. (args.warning and "\n*'備註：'" .. args.warning or '') or args.warning or '-' ) elseif args.type 'Item' and args.effect then result :_'\n Effect \n\n' :_(string.gsub(args.effect, '\n', ' ')) end end result :_(args.notes and "\n Notes \n") :_(args.notes) :_'\n 製作配方 \n' :_(args.recipe and args.recipe ~= 'none' and string.format( ' ', args.rec_mat and split_link(args.rec_mat, nil, ' ', function(v) local item, quantity = string.match(v, '(^%(-) ?%(?(%d+)') return string.format(' ', item or v, quantity or 1) end ), args.rec_gil or '?', args.time or '?') or '無' ) :_((args.usage or args.quest) and result :_"\n Usage " :_(args.usage and "\n''Crafting Material" .. multi_split(args.usage, "\n:%s\n::*", '\n::*', '\n:*')) :_(args.quest and "\n''Involved in Quest''\n:*" .. split_link(args.quest, nil, '\n:*')) ._noop--just a hack to return nil ) :_"\n 獲得方式 " for i = 1, #froms, 1 do if args[fromsi1] then result :_"\n":_(fromsi2) :_"\n*":_(split_link(args[fromsi1], nil, '\n*')) end end result :_(args.trust and string.format("\n信賴度滿點報酬''\n*%s", args.trust)) :_(args.obtain and multi_split(args.obtain, "\n''%s''\n:*", '\n:*', '\n*')) :_(args.used_by and "\n 專用兵員 \n*" .. split_link(args.used_by, nil, '\n*')) local categories = {'\n[if args.type and p.equipment[args.type then table.insert(categories, '裝備') if args.type '首飾' then table.insert(categories, '首飾') else table.insert(categories, p.equipment._class[p.equipmentargs.type]) table.insert(categories, p.equipment._pluralargs.type or args.type) end end for _, k in ipairs{ --{arg key, category name}, if key is not nil, put in cat {'recipe', '可製作'}, {'buy_gil', '可購買'}, {'trust', '信賴度滿點報酬'}, {hasExclusiveFX and 'effect' or 'used_by', '兵員專用物品'}, {'usage', '製作素材'}, {'quest', '任務物品'} } do if args[k1] then table.insert(categories, k2) end end result :_(mw.title.getCurrentTitle().namespace ~= 0 and --escape catagories if not on main namespace string.gsub(table.concat(categories, ']]\nCategory:'), '%[C', '[:C') or table.concat(categories, '\nCategory:') ) :_'' end return frame:preprocess(table.concat(result)) end return p